def IntersectionArea(x1, y1, x2, y2, x3, y3, x4, y4):
    min1X = x1
    max1X = x2
    min1Y = y1
    max1Y = y2

    min2X = x3
    max2X = x4
    min2Y = y3
    max2Y = y4

    X1 = max(min1X, min2X)
    X2 = min(max1X, max2X)
    Y1 = max(min1Y, min2Y)
    Y2 = min(max1Y, max2Y)

    if X2 - X1 < 0 or Y2 - Y1 < 0:
        Area = 0
        return Area

    else:
        Area = abs(Y2 - Y1) * abs(X2 - X1)

        return Area


def Predict(myTrackerList,xStep,yStep,minX,maxX,widthStep,direct):
    delList = []
    for temp in myTrackerList:
        temp.x1 = temp.x1 + xStep
        temp.y1 = temp.y1 + yStep
        temp.x2 = temp.x2 + xStep
        temp.y2 = temp.y2 + yStep
        xcenter = (temp.x1 + temp.x2) / 2
        temp.checked = False
        if direct == 1:
            if xcenter < minX or xcenter > maxX-widthStep/2:
                delList.append(temp)
        else:
            if xcenter < minX+widthStep/2 or xcenter > maxX:
                delList.append(temp)
    for delt in delList:
        myTrackerList.remove(delt)

    return myTrackerList


def Area(x1, y1, x2, y2):
    lens = x2 - x1
    wide = y2 - y1
    res = lens * wide
    return res
